package com.quasar.hpatient.view.personal.register.registerFragment;

import android.widget.RadioButton;

import com.quasar.hpatient.R;
import com.quasar.hpatient.base.BaseFragment;
import com.quasar.hpatient.constant.ConstantManger;
import com.quasar.hpatient.model.httpmodel.DataStateResult;
import com.quasar.hpatient.model.medicalmodel.PatientInfoData;
import com.quasar.hpatient.onInterface.viewInterface.UiInterface;
import com.quasar.hpatient.presenter.AloneUserPresenter;
import com.quasar.hpatient.view.personal.register.RegisterEditActivity;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EFragment;
import org.androidannotations.annotations.FragmentArg;
import org.androidannotations.annotations.ViewById;

/**
 * author : 许建宏
 * Date: 2017/11/27 0027
 * View:注册性别
 */

@EFragment(R.layout.register_sex_fragment_layout)
public class RegisterSexFragment extends BaseFragment implements UiInterface<DataStateResult> {

    private AloneUserPresenter aloneUserPresenter;
    //性别
    @ViewById(R.id.btn1)
    RadioButton btn1;
    @ViewById(R.id.btn2)
    RadioButton btn2;
    @FragmentArg
    PatientInfoData patient;


    @AfterViews
    void init() {
        initView();
        initData();
    }

    @Override
    public void initView() {
        if (patient.getSex() == 1) {
            btn1.setChecked(true);
        } else {
            btn2.setChecked(true);
        }
    }

    @Override
    public void initData() {
        aloneUserPresenter = new AloneUserPresenter(this);
    }

    @Click(R.id.tv_next)
    public void tv_next() {

        //性别
        int sex;
        if (btn1.isChecked()) {
            sex = 1;
        } else {
            sex = 0;
        }

        showDialog();
        aloneUserPresenter.AloneUserData(ConstantManger.USERSEX, sex + "", ConstantManger.TABLEUSERINFO);
    }

    @Click(R.id.tv_last)
    public void tv_last() {
        RegisterEditActivity.ViewPage(0);
    }

    @Click(R.id.tv_skip)
    public void tv_skip() {
        RegisterEditActivity.ViewPage(2);
    }

    @Override
    public void onViewSuccess(DataStateResult data) {

        if (data.getMsgCode().equals("0x00000000")) {
            RegisterEditActivity.ViewPage(2);
        }
        dessDialog();
    }

    @Override
    public void onViewError(String msg) {
        if (msg != null) {
            msg(msg);
        }
        dessDialog();
    }

    @Override
    public void onViewRefreshUI() {
        dessDialog();
    }

}
